// VincentDoc.cpp : implementation of the CVincentDoc class
//

#include "stdafx.h"
#include "Vincent.h"

#include "VincentDoc.h"

#include "MainFrm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CVincentDoc

IMPLEMENT_DYNCREATE(CVincentDoc, CDocument)

BEGIN_MESSAGE_MAP(CVincentDoc, CDocument)
	//{{AFX_MSG_MAP(CVincentDoc)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CVincentDoc construction/destruction

CVincentDoc::CVincentDoc()
{
	// 새 문서를 만들때 참조할 값을 정의한다.
	m_colorNewDocForeground = RGB(0,0,0);
	m_colorNewDocBackground = RGB(255,255,255);
	m_sizeImage.cx = m_sizeNewDocument.cx = 640;
	m_sizeImage.cy = m_sizeNewDocument.cy = 480;
}

CVincentDoc::~CVincentDoc()
{
}

BOOL CVincentDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;
	
	// ResetDocument()에서 설정한 값, 또는 생성자에서 만들어진 값을 대입한다.
	m_sizeImage = m_sizeNewDocument;
	m_rgbForeground = m_colorNewDocForeground;
	m_rgbBackground = m_colorNewDocBackground;
	
	
//	CString test;
//	test.Format("%d", ((CMainFrame*)AfxGetMainWnd())->GetActiveView()->GetDC());
//	test.Format("%d", ((CMainFrame*)AfxGetMainWnd())->GetActiveView());
//	AfxMessageBox(test);
///*
	// 새 문서 생성. 히스토리를 비우고, 캐쉬를 초기화 한다.
	m_WorkHistory.Initialize(m_colorNewDocBackground, m_sizeImage);
	
	m_nPenWidth = 1;	// 펜 굵기를 1로
	m_bFillOut = TRUE;	// 색칠 하는 것으로 설정
	
	m_nToolBarID = ID_TOOLS_FREEDRAW;	// 툴바를 FreeDraw로 설정
	
	//	색상 선택 다이얼로그바랑, 뷰를 업데이트 새로 그려준다.
	UpdateAllViews(NULL);
	//((CMainFrame*)AfxGetMainWnd())->GetColorDlgBar()->InvalidateRect(NULL, TRUE);
//*/
	
	return TRUE;
}

BOOL CVincentDoc::OnResetDocument(CSize imagesize, COLORREF foreground, COLORREF background)
{
	m_sizeNewDocument = imagesize;
	m_colorNewDocForeground = foreground;
	m_colorNewDocBackground = background;
	return OnNewDocument();
}



/////////////////////////////////////////////////////////////////////////////
// CVincentDoc serialization

void CVincentDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}

/////////////////////////////////////////////////////////////////////////////
// CVincentDoc diagnostics

#ifdef _DEBUG
void CVincentDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CVincentDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CVincentDoc commands

CSize CVincentDoc::GetImageSize()
{
	return m_sizeImage;
}

CWorkHistory* CVincentDoc::GetWorkHistory()
{
	return &m_WorkHistory;
}

// 전경색을 설정한다.
void CVincentDoc::SetForegroundColor(COLORREF color)
{
	m_rgbForeground = color;
	//((CMainFrame*)AfxGetMainWnd())->GetColorDlgBar()->InvalidateRect(NULL, TRUE);
}

// 전경색을 얻어온다.
COLORREF CVincentDoc::GetForegroundColor()
{
	return m_rgbForeground;
}

// 배경색을 설정한다.
void CVincentDoc::SetBackgroundColor(COLORREF color)
{
	m_rgbBackground = color;
	//((CMainFrame*)AfxGetMainWnd())->GetColorDlgBar()->InvalidateRect(NULL, TRUE);
}

// 배경색을 얻어온다.
COLORREF CVincentDoc::GetBackgroundColor()
{
	return m_rgbBackground;
}

void CVincentDoc::SetFillOut(BOOL fill)
{
	m_bFillOut = fill;
}

BOOL CVincentDoc::GetFillOut()
{
	return m_bFillOut;
}

void CVincentDoc::SetPenWidth(int width)
{
	m_nPenWidth = width;
}

int CVincentDoc::GetPenWidth()
{
	return m_nPenWidth;
}

UINT CVincentDoc::GetToolsType()
{
	return m_nToolBarID;
}

void CVincentDoc::SetToolsType(UINT nID)
{
	m_nToolBarID = nID;
}

CDC* CVincentDoc::GetCacheDC()
{
	return m_WorkHistory.GetCacheDC();
}
